const dockerBuildManager = require('./src/utils/dockerBuildManager');
const path = require('path');

async function testDockerBuild() {
  try {
    console.log('🧪 测试Docker构建功能...');
    
    // 检查Docker是否可用
    const dockerAvailable = await dockerBuildManager.checkDockerAvailable();
    console.log('Docker可用性:', dockerAvailable);
    
    if (!dockerAvailable) {
      console.log('❌ Docker不可用，请确保Docker Desktop已启动');
      return;
    }
    
    // 创建一个简单的测试项目
    const testProjectPath = path.join(__dirname, 'test-project');
    const fs = require('fs-extra');
    
    // 创建测试目录
    await fs.ensureDir(testProjectPath);
    
    // 创建package.json
    const packageJson = {
      name: 'test-project',
      version: '1.0.0',
      scripts: {
        build: 'echo "Build completed" && mkdir -p dist && echo "Hello Docker Build!" > dist/index.html'
      },
      dependencies: {
        'express': '^4.17.1'
      }
    };
    
    await fs.writeJson(path.join(testProjectPath, 'package.json'), packageJson, { spaces: 2 });
    
    console.log('📁 创建测试项目完成');
    
    // 测试Docker构建
    console.log('🐳 开始Docker构建测试...');
    const result = await dockerBuildManager.buildWithDocker(testProjectPath, 'node14', {});
    
    console.log('✅ Docker构建结果:', result);
    
    // 清理测试项目
    await fs.remove(testProjectPath);
    console.log('🧹 清理测试项目完成');
    
  } catch (error) {
    console.error('❌ Docker构建测试失败:', error);
  }
}

testDockerBuild();
